<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 递归，自己调用自己
    //累加器
    // function getNum(n) {
    //     if (n ==1) {
    //         return 1
    //     } else {
    //         return n + getNum(n - 1)
    //     }
    // }
    // console.log(getNum(30))
    // // // 递归深拷贝
    var obj = {
        name: 'zs',
        age: 18,
        object: {
            age: 20
        }
    }
    var newObj = {}
    function recursion(obj, newObj) {
        for (key in obj) {
            if (obj[key].constructor== Object){
                newObj[key]={}
                recursion(obj[key], newObj[key])
            }
            else if(obj[key].constructor==Array){
                newObj[key]=[]
                recursion(obj[key], newObj[key])
            }
            else {
                newObj[key]=obj[key]
            }
        }
    }
    recursion(obj, newObj)
    newObj.object.age=50
    console.log(obj)
    console.log(newObj)

</script>

</html>